﻿using System.Collections.Generic;
using System.Linq;

namespace HamcoWcs.Models.Devices
{
    public enum EnumMachineControlState
    {
        ONLINEREMOTE,
        ONLINELOCAL,
        OFFLINE
    }

    public enum EnumMachineState
    {
        RUN,
        DOWN,
        PM,
        BLOCK,
        IDLE,
        NONE
    }
    //public class MachineDto
    //{
    //    public MachineDto(string machineName)
    //    {
    //        MachineName = machineName;
    //    }

    //    public string MachineName { get; set; }

    //    public EnumMachineControlState MachineControlState { get; set; }
    //    public EnumMachineState MachineState { get; set; }

    //    public Dictionary<int, PconDto> MachinePorts { get; set; } = new Dictionary<int, PconDto>();

    //    public void UpdatePcon(PconDto pcon)
    //    {
    //        //var pcon = MachinePorts.GetValueOrDefault(pcon.PconName);
    //        MachinePorts[pcon.PconName] = pcon;
    //    }
    //    public void AddPcon(PconDto pcon)
    //    {
    //        //if (!MachinePorts.ContainsKey(pcon.PconName))
    //        //    MachinePorts.Add(pcon.PconName, pcon);

    //        //pcon.Machine = this;

    //        //UpdateControlState();
    //        //UpdateState();
    //    }

    //    public bool UpdateControlState()
    //    {
    //        var pcons = MachinePorts.Values.ToList();
    //        bool isAuto = pcons.Any(x => x.PconMode != 1);

    //        var old = MachineControlState;

    //        if (pcons.All(x => x.PconMode == 1))
    //        {
    //            this.MachineControlState = EnumMachineControlState.ONLINEREMOTE;
    //        }
    //        else if (pcons.Any(x => x.PconMode == 0))
    //        {
    //            this.MachineControlState = EnumMachineControlState.OFFLINE;
    //        }
    //        else
    //        {
    //            this.MachineControlState = EnumMachineControlState.ONLINELOCAL;
    //        }

    //        return old != this.MachineControlState;
    //    }
    //    public bool UpdateState()
    //    {
    //        var pcons = MachinePorts.Values.ToList();

    //        var old = MachineState;
    //        if (pcons.All(x => x.PconMode == 1))
    //        {
    //            this.MachineState = EnumMachineState.RUN;
    //        }
    //        else
    //        {
    //            this.MachineState = EnumMachineState.DOWN;
    //        }

    //        return old != MachineState;
    //    }
    //}


}
